package com.zhangmeng.online.exam.ui.utils;

import com.zhangmeng.online.exam.ui.api.form.*;
import com.zhangmeng.online.exam.ui.api.form.base.Form;
import com.zhangmeng.online.exam.ui.components.DynamicTableComponent;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author zm
 * @date 2025/3/31 15:48
 * @version: 1.0
 */
public class FxUtils {

    public final static double DEFAULT_WIDTH = 1280;
    public final static double DEFAULT_HEIGHT = 720;

    public static final Map<String, DynamicTableComponent> FX_BEANS = new HashMap<>();

    public static String Question_DynamicTableComponent;
    public static String Role_DynamicTableComponent;
    public static String User_DynamicTableComponent;
    public static String Paper_DynamicTableComponent;
    public static String Subject_DynamicTableComponent;
    public static String QuestionOption_DynamicTableComponent;
    public static String Permission_DynamicTableComponent;
    public static String Profession_DynamicTableComponent;
    public static String Exam_DynamicTableComponent;


    public static void alert(String title, Parent node, Stage primaryStage) {

        Form form = (Form) node;
        if (form instanceof UserForm) {
            form = new UserForm();
        }
        if (form instanceof RoleForm) {
            form = new RoleForm();
        }

        if (form instanceof QuestionForm) {
            form = new QuestionForm();
        }

        if (form instanceof SubjectForm) {
            form = new SubjectForm();
        }

        if (form instanceof QuestionOptionForm){
            form = new QuestionOptionForm();
        }

        Scene scene = new Scene(form);
        Stage dialogStage = new Stage();
        dialogStage.setTitle(title);
        dialogStage.setResizable(false);
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        dialogStage.setScene(scene);
        dialogStage.showAndWait();

    }

    public static void alert(String title, Parent node, Stage primaryStage, boolean isEdit) {

        Form form = (Form) node;
        if (form instanceof UserForm) {
            form = new UserForm();
        }
        if (form instanceof RoleForm) {
            form = new RoleForm();
        }

        if (form instanceof QuestionForm) {
            form = new QuestionForm();
        }

        if (form instanceof PaperForm){
            form = new PaperForm();
        }

        if (form instanceof PermissionForm){
            form = new PermissionForm();
        }

        if (form instanceof SubjectForm){
            form = new SubjectForm();
        }

        if (form instanceof QuestionOptionForm){
            form = new QuestionOptionForm();
        }

        Scene scene = null;
        if (!isEdit) {
            scene = new Scene(form);
        }else {
            scene = new Scene(node);
        }

        Stage dialogStage = new Stage();
        dialogStage.setTitle(title);
        dialogStage.setResizable(false);
        dialogStage.initModality(Modality.WINDOW_MODAL);
        dialogStage.initOwner(primaryStage);
        dialogStage.setScene(scene);
        dialogStage.showAndWait();

    }
}
